{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="{% static 'js/lib/layui/css/layui.css' %}">
            <link rel="stylesheet" href="{% static 'css/common.css' %}">

</head>
<body>

<div class="layui-container" style="margin-top: 30px">
    <div class="layui-row">
        <input type="text" style="display: none;" name="model_id" id="model_id" value="{{ model_obj.id }}">

        <div style="margin-top: 10px;">
            <div style="margin-top: 10px;margin-bottom: 5px;">
                <label style="font-weight: bold;color: #333333">知识推理模型名称</label>
            </div>
            <input type="text" style="margin: 10px 0 20px" name="model_name" id="model_name" class="layui-input my-input" value="{{ model_obj.name }}" readonly>
        </div>
        <div style="margin-top: 10px;">
            <div style="margin-top: 10px;margin-bottom: 5px;">
                <label style="font-weight: bold;color: #333333">参数(开始节点uuid)</label>
            </div>
            <input type="text" style="margin: 10px 0 20px" name="start_node_uuid" id="start_node_uuid" class="layui-input my-input" value="{{ model_obj.start_node_uuid }}">
        </div>
        <div style="margin-top: 10px;">
            <div style="margin-top: 10px;margin-bottom: 5px;">
                <label style="font-weight: bold;color: #333333">参数(关系类型)</label>
            </div>
            <input type="text" style="margin: 10px 0 20px" name="relation_type" id="relation_type" class="layui-input my-input" value="{{ model_obj.relation_type }}">
        </div>
    </div>

    <div>
        <button type="submit" class="my-btn" style="float: right;margin-top: 20px" id="sub"> 确认</button>
    </div>
</div>
</div>

<script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/lib/layui/layui.js' %}"></script>
<script>

    $('#sub').click(function () {
        var id = $('#model_id').val();
        var name = $('#model_name').val();
        var start_node_uuid = $('#start_node_uuid').val();
        var relation_type = $('#relation_type').val();

        if (name === undefined) {
            alert("模型名称不能为空！！！");
        } else if (start_node_uuid === undefined) {
            alert("参数(开始节点uuid)不能为空！！！");
        } else if (relation_type === undefined) {
            alert("参数(关系类型)不能为空！！！");
        } else {
            $.ajax({
                url: '{% url 'knowledge_reasoning_model_edit' %}',
                type: 'post',
                data: {'id': id, 'name': name, 'start_node_uuid': start_node_uuid, 'relation_type': relation_type},
                success: function (res) {
                    if (res["code"] == "1") {
                        window.parent.layer.closeAll();
                        window.parent.location.href = '{% url "data_mining_model" %}?sign=1';
                        // window.parent.location.reload();
                    } else {
                        alert(res["msg"]);
                    }
                }
            })
        }
    });
</script>

</body>
</html>